﻿namespace ap2.Phone.Core.Data
{
    using System.IO.IsolatedStorage;

    public class Storage
    {
        public sealed class SettingsIndexer
        {
            public object this[string setting]
            {
                get
                {
                    if (!IsolatedStorageSettings.ApplicationSettings.Contains(setting))
                    {
                        return null;
                    }
                    return IsolatedStorageSettings.ApplicationSettings[setting];
                }
                set
                {
                    if (!IsolatedStorageSettings.ApplicationSettings.Contains(setting))
                    {
                        IsolatedStorageSettings.ApplicationSettings.Add(setting, value);
                    }
                    else
                    {
                        IsolatedStorageSettings.ApplicationSettings[setting] = value;
                    }
                }
            }

            public void Remove(string setting)
            {
                if (IsolatedStorageSettings.ApplicationSettings.Contains(setting))
                {
                    IsolatedStorageSettings.ApplicationSettings.Remove(setting);
                }
            }
        }

        private static SettingsIndexer StaticIndexer;

        public static SettingsIndexer Setting
        {
            get { return StaticIndexer ?? (StaticIndexer = new SettingsIndexer()); }
        }
    }
}
